package com.yh.correct.service.impl;

import com.yh.correct.dao.ICommunityAdminMainMapper;
import com.yh.correct.model.CommunityAdmin;
import com.yh.correct.model.CommunityAdminMain;
import com.yh.correct.model.Page;
import com.yh.correct.service.ICommunityAdminMainService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * Created by 孙瑞豪 on 2017-03-08.
 *
 * 描述: 实现社区刑人员管理接口服务
 */
@Service
public class CommunityAdminMainServiceImpl implements ICommunityAdminMainService{

    private static Logger logger = LogManager.getLogger(ExpireServiceImpl.class);
    @Autowired
    private ICommunityAdminMainMapper icam;
    /**
     * 作者:孙瑞豪
     * 创建时间:2017-03-08
     * 描述: 添加服刑人员档案
     * @throws Exception
     */
    @Override
    public int addCommunityAdminMain(CommunityAdminMain ca) throws Exception {
        // TODO Auto-generated method stub
        return icam.addCommunityAdminMain(ca);
    }

    /**
     * 作者:孙瑞豪
     * 创建时间:2017-03-08
     * 描述: 根据id查询服刑人员详细信息
     * @throws Exception
     */
    @Override
    public Map getCommunityAdminMain(CommunityAdminMain ca) throws Exception {
        // TODO Auto-generated method stub
        return icam.getCommunityAdminMain(ca);
    }

    /**
     * 作者:孙瑞豪
     * 创建时间:2017-03-08
     * 描述: 根据id删除服刑人员详细信息
     * @throws Exception
     */
    @Override
    public int delCommunityAdminMain(CommunityAdminMain ca) throws Exception {
        // TODO Auto-generated method stub
        return icam.delCommunityAdminMain(ca);
    }

    /**
     * 作者:孙瑞豪
     * 创建时间:2017-03-08
     * 描述: 模糊查询匹配的用户
     * @throws Exception
     */
    @Override
    public Page getLikeAdminMainCount(Map<String, Object> cont) throws Exception {
        Page page = new Page();
        page.setTotalNum(icam.getLikeCommunityAdminMainCount(cont));
        int pageSize = Integer.parseInt(String.valueOf(cont.get("pageSize")));
        page.setPageSize(pageSize);
        int pageNum = Integer.parseInt(String.valueOf(cont.get("pageNum")));
        page.setCurPageNum(pageNum);
        page.setTotalPage(page.getTotalNum() / pageSize + (page.getTotalNum() % pageSize == 0 ? 0 : 1));
        page.setResult(icam.getALLCommunityAdminMain(cont));
        return page;
    }

    /**
     * 作者:孙瑞豪
     * 创建时间:2017-03-15
     * 描述: 查询下一个档案id
     * @throws Exception
     */
    @Override
    public Integer getLastId() throws Exception{
        return icam.getLastId();
    }


    /**
     * 作者:孙瑞豪
     * 创建时间:2017-03-15
     * 描述: 更新下载日期
     * @throws Exception
     */
    @Override
    public Integer update(CommunityAdminMain ca) throws Exception {
        // TODO Auto-generated method stub
        return icam.updateById(ca);
    }


    /**
     * @author comcn155 修改档案
     * @param ca
     * @return
     * @throws Exception
     */
    @Override
    public int editCommunityAdminMain(CommunityAdminMain ca) throws Exception {
        return icam.editCommunityAdminMain(ca);
    }
}
